package main

import "fmt"

/**
结构体数组
*/
func main() {

	//定义结构体数组
	var arr [5]student = [5]student{
		{101, "ll", 19, "bj"},
		{102, "ll", 19, "bj"},
		{103, "ll", 19, "bj"},
		{104, "ll", 19, "bj"},
		{105, "ll", 19, "bj"}, //这里的逗号不能省略
	}
	fmt.Println(arr)
	//[{101 ll 19 bj} {102 ll 19 bj} {103 ll 19 bj} {104 ll 19 bj} {105 ll 19 bj}]
	s := arr[0]
	//输出相应属性
	fmt.Println(s.age)
	//获取结构体中数据
	for _, v := range arr {
		fmt.Println(v.age)
		fmt.Println(v.name)
	}
	//修改结构体中内容
	arr[0].name = "aaaa"

	for i := 0; i < len(arr); i++ {
		fmt.Println(arr[i])
	}
}

/**
结构体作用域在在函数外面
全局的作用域
*/
type student struct {
	//这里不能加var关键字
	id   int
	name string
	age  int
	addr string
}
